package com.osremake.server.net;

import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;

/**
 * @author kyle
 */
public class Buffer {
    private int opcode;
    private Packet.Type type;
    private ChannelBuffer buffer;

    public Buffer() {
        this(-1);
    }

    public Buffer(int opcode) {
        this(opcode, Packet.Type.FIXED);
    }

    public Buffer(int opcode, Packet.Type type) {
        this.opcode = opcode;
        this.type = type;
        buffer = ChannelBuffers.dynamicBuffer(128);
    }

    public Packet toPacket() {
        return new Packet(opcode, buffer.writerIndex(), type, buffer);
    }
}
